<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jquery.js"></script>
    <style>
        .red {
            border: 1px red solid;
            height: 300px;
            width: 400px;
        }

        .blue {
            border: 1px blue solid;
            height: 50px;
            width: 200px;
        }
    </style>
</head>

<body>
<video id="video"  autoplay playsinline  class="red"></video>
<button onclick="video()">开始视屏</button>
<audio id="audio" controls autoplay  class="blue" >
</audio><button onclick="audio()">开始声音</button>
</body>
<script type="text/javascript">
    let stream=null;
    async function video(){
        let constraints = {
            video: true,
            audio: false
        };
      stream = await navigator.mediaDevices.getUserMedia(constraints);
        document.getElementById("video").srcObject=stream;
    }

    async function audio(){
        stream=null;
        let constraints = {
            video: false,
            audio: true
        };

        stream = await navigator.mediaDevices.getUserMedia(constraints);
        document.getElementById("audio").srcObject=stream;
    }


</script>

</html>